
package org.aha.ahaxproject.servlet.xmlreqservlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.cm.xmloperations.XmlOperationFactory;
import org.japril.jutil.xmloperations.XmlOperations;
import org.japril.servlet.WebAppUser;
import org.japril.servlet.xmlservlet.EngineHandler;
import org.japril.servlet.xmlservlet.EnvironmentInitializer;
import org.japril.servlet.xmlservlet.ResponseHandler;

public final class MyEnvironmentInitializer implements EnvironmentInitializer,
  EngineHandler, ResponseHandler
{
  private String m_resp="nothing done";
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public MyEnvironmentInitializer(){}
  
  //
  // EnvironmentInitializer.
  //
  
  // Specified in EnvironmentInitializer.
  public Object initialize(String xml) throws IOException { return xml; }
  
  // Specified in EnvironmentInitializer.
  public EngineHandler getEngineHandler(){ return this; }

  // Specified in EnvironmentInitializer.
  public ResponseHandler getResponseHandler(){ return this; }

  //
  // EngineHandler.
  //
  
  // Specified in EngineHandler. 
  public void perform(String xml, Object o) throws IOException
  {
    XmlOperations ops=XmlOperationFactory.create();
    ops.doLog(false);
    m_resp=ops.perform(xml);
  }

  //
  // ResponseHandler.
  //
  
  // Specified in ResponseHandler. 
  public void perform(WebAppUser wau, String xml, Object o, 
    HttpServletResponse resp) throws IOException
  {
    resp.setContentType("text/plain");
    PrintWriter pw=resp.getWriter();
    pw.println(m_resp);
  }
  
}
